<?php
/**
 * FAS 救援大厅
 *
 * Date: 2018/1/9 
 * @author jackzheng
 */
include_once(GZ_PATH . '/includes/fas_func.php');
include_once(GZ_PATH . '/includes/rescue_func.php');
require(GZ_PATH . '/library/ypsms_class.php');
class faslobbyAction extends Action{

	/**
	 * FAS 求助事件列表
	*/
	public function  get_list(){
		
		 $status=_POST('status','');
		 $page_size   = GZ_Api::$pagination['count'];    //分页设置
		 $page        = GZ_Api::$pagination['page'];     //分页设置
		 $res=get_rescueList($status,$page,$page_size);
		 if($res){
			GZ_Api::outPut($res);
		  }else{
			GZ_Api::outPut(13);
		 }
	
	}
	
	/**
	 * FAS 求助事件详情
	*/
	public function  get_details(){

		 $id=_POST('log_id','');
		 $data=get_fas_details($id);//求助详情
	 
		if(!empty($data)){
			GZ_Api::outPut($data); 
		}else{
			 GZ_Api::message("数据不存在",0);
		}

	}
	
	
	/**
	 *确认救援
	*/
	public function confirm_rescue(){
		 $data=array();
		 $user_id = _POST('user_id',0);
		 $id=_POST('log_id',0);
		 $coordinate = _POST('coordinate','');
		 
		 $user_info=$this->getRow('select user_rank,user_name from '.$this->table('users').' where user_id='.$user_id);
		 if($user_info['user_rank']!=2){
			GZ_Api::message("您还不是爱心用户,不能进行救援！！！",2);
		 }
	 
		$rescue = $this->getRow('select status,pay_status,user_id from '.$this->table('rescue_log').' where id='.$id);
		
		if($rescue){
			
			if($rescue['status']==0){
				$data['rescue_id'] = $user_id;
				$data['agree_time'] = time();
				$data['status'] = 1;
				$data['rescue_coordinate'] = json_encode($coordinate);
				$res = $this->autoExecute($this->table('rescue_log'), $data, 'UPDATE', "id = ".$id);
				
				if($res){
				//===============发送信息通知=================
					$phone=$this->getOne('select user_phone from '.$this->table('users').' where user_id='.$rescue['user_id']);//求助人的手机号
					$ypsms = new ypsms();
					$res_data = $ypsms->send_msg($phone,$user_info['user_name']);
				//==========================================
					
				  GZ_Api::message("救援行为已确认，请尽快前往",1);
				}else{
				  GZ_Api::message("发起救援请求出错，请重试",2);
				}
			}
			
			if($rescue['status']==1){
				 GZ_Api::message("已有他人前往救援！！！",2);
			}
			if($rescue['status']==2){
				GZ_Api::message("救援请求已结束",2);
			}
			if($rescue['status']==4){
				GZ_Api::message("救援请求已取消",2);
			}
			
		 }else{
			 GZ_Api::message("信息不存在",0);
		 }

     
	}
	
	
}


?>